package com.woniu.his.sms.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniu.his.result.Result;
import com.woniu.his.sms.client.SmsDeptManageClient;
import com.woniu.his.sms.client.param.AddDeptParam;
import com.woniu.his.sms.client.param.UpdateDeptParam;
import com.woniu.his.sms.service.DeptService;
import com.woniu.his.sms.service.DeptTypeService;
import com.woniu.his.sms.service.param.AddDeptServiceParam;
import com.woniu.his.sms.service.param.UpdateDeptServiceParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/sms")
public class SmsDeptManageApiImpl implements SmsDeptManageClient {

    @Resource
    private DeptTypeService deptTypeService;

    @Resource
    private DeptService deptService;


    @Override
    public Result addDept(@Valid AddDeptParam param) {

        log.info("新增科室的入参为：{}",param);
        AddDeptServiceParam addDeptParam = BeanUtil.copyProperties(param,AddDeptServiceParam.class);
        deptService.addDept(addDeptParam);
        return Result.getInstance();
    }

    @Override
    public Result addDeptType(String deptTypeName) {

        log.info("科室类别名为：{}",deptTypeName);
        deptTypeService.addDeptType(deptTypeName);

        return Result.getInstance();
    }

    @Override
    public Result deleteDeptByIds(List<Integer> ids) {

        log.info("传回来的科室IDS为：{}",ids);
        deptService.deleteDeptByIds(ids);
        return Result.getInstance();
    }

    @Override
    public Result updateDeptById(@Valid UpdateDeptParam param) {

        log.info("更新科室传回来的信息：{}",param);
        UpdateDeptServiceParam updateDeptServiceParam=BeanUtil.copyProperties(param, UpdateDeptServiceParam.class);
        deptService.updateDeptById(updateDeptServiceParam);
        return Result.getInstance();
    }
}
